package com.lj.sys.result;

import com.lj.sys.entity.SysLogEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;

/**
 * <p>
 * 系统日志 分页结果
 * </p>
 *
 * @author luojing
 * @since 2025-04-18 17:22:24
 */
@Data
@Schema(description = "系统日志 分页结果")
public class SysLogPageResult {

    @Schema(description = "日志名称 ")
    private String logName;

    @Schema(description = "请求ip ")
    private String ip;

    @Schema(description = "请求url ")
    private String url;

    @Schema(description = "请求方法 ")
    private String method;

    @Schema(description = "执行方法名称 ")
    private String methodName;

    @Schema(description = "是否执行成功 ")
    private Boolean succeed;

    @Schema(description = "错误信息 ")
    private String error;

    @Schema(description = "请求参数 ")
    private String paramsJson;

    @Schema(description = "执行结果 ")
    private String resultJson;

    @Schema(description = "执行耗时(ms) ")
    private Long duration;

    @Schema(description = "创建时间 ")
    private LocalDateTime createTime;

    public static SysLogPageResult of(SysLogEntity entity) {
        if (entity == null) {
            return null;
        }
        SysLogPageResult result = new SysLogPageResult();
        result.setLogName(entity.getLogName());
        result.setIp(entity.getIp());
        result.setUrl(entity.getUrl());
        result.setMethod(entity.getMethod());
        result.setMethodName(entity.getMethodName());
        result.setSucceed(entity.getSucceed());
        result.setError(entity.getError());
        result.setParamsJson(entity.getParamsJson());
        result.setResultJson(entity.getResultJson());
        result.setDuration(entity.getDuration());
        result.setCreateTime(entity.getCreateTime());
        return result;
    }
}
